package kang.zhoujin.util;

import java.awt.AWTException;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.MouseEvent;

public class MouseUtil {
	private Robot robot = null;
	public MouseUtil() throws AWTException{
		robot = new Robot();
	}

	public void moveTo(int x,int y){
		robot.mouseMove(x, y);	
	}

	public void moveTo(Point point){
		robot.mouseMove(point.x, point.y);	
	}

	public void moveTo(String pointStr){
		String[] ss = pointStr.split(",");
		int x = Integer.parseInt(ss[0]);
		int y = Integer.parseInt(ss[1]);
		robot.mouseMove(x, y);	
	}

	public void leftClick(){
		robot.mousePress(MouseEvent.BUTTON1_MASK);
		robot.mouseRelease(MouseEvent.BUTTON1_MASK);
	}

	public void leftClick(int times){
		for(int i = 0; i < times; i++){
			robot.mousePress(MouseEvent.BUTTON1_MASK);
			robot.mouseRelease(MouseEvent.BUTTON1_MASK);
			try{
				Thread.sleep(400);
			} catch (Exception e){

			}
		}
	}

	public void rightClick(){
		robot.mousePress(MouseEvent.BUTTON3_MASK);
		robot.mouseRelease(MouseEvent.BUTTON3_MASK);
	}

	public void rightClick(int times){
		for(int i = 0; i < times; i++){
			robot.mousePress(MouseEvent.BUTTON3_MASK);
			robot.mouseRelease(MouseEvent.BUTTON3_MASK);
		}
	}

	public void leftPress(){
		robot.mousePress(MouseEvent.BUTTON1_MASK);
	}

	public void leftRelease(){
		robot.mouseRelease(MouseEvent.BUTTON1_MASK);
	}

	public void rightPress(){
		robot.mousePress(MouseEvent.BUTTON3_MASK);
	}

	public void rightRelease(){
		robot.mouseRelease(MouseEvent.BUTTON3_MASK);
	}

}
